package com.launcher.wkang.receive;



import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.TextView;

/**
 * 监听获取手机系统剩余电量
 * Created by Lx on 2016/9/17.
 */
public class BatteryReceiver extends BroadcastReceiver {


    public BatteryReceiver() {

    }

    @Override
    public void onReceive(Context context, Intent intent) {
        int current = intent.getExtras().getInt("level");// 获得当前电量
        int total = intent.getExtras().getInt("scale");// 获得总电量
        int percent = current * 100 / total;
//        pow.setText(percent + "%");
        Log.d("BatteryReceiver","BatteryReceiver percent="+percent);
        SharedPreferences sharedPreferences =context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("current",current);
        editor.putInt("total",total);
        editor.commit();
    }
}
